package blaha.genalg.methods;

import org.apache.log4j.Logger;

import blaha.genalg.beans.Point;
import blaha.logging.Log;

public class CountDistance {

	private static final Logger log = Log.getLoggerMoje();

	public static float betweenTwoPoints(Point a, Point b) {
		try {
			Integer xZeroPos = 0;
			Integer yZeroPos = 0;
			// X
			// x1=>0 && x2 =>0
			if (a.x >= 0 && b.x >= 0)
				xZeroPos = Math.abs(a.x - b.x);
			// x1<0 && x2 =>0
			if (a.x < 0 && b.x >= 0)
				xZeroPos = Math.abs(a.x) + b.x;
			// x1=>0 && x2 <0
			if (a.x >= 0 && b.x < 0)
				xZeroPos = a.x + Math.abs(b.x);
			// x1<0 && x2<0
			if (a.x < 0 && b.x < 0)
				xZeroPos = Math.abs(a.x + Math.abs(b.x));

			// Y
			// y1>=0 && y2>=0
			if (a.y >= 0 && b.y >= 0)
				yZeroPos = Math.abs(a.y - b.y);
			// y1>=0 && y2<0
			if (a.y >= 0 && b.y < 0)
				yZeroPos = a.y + Math.abs(b.y);
			// y1<0 && y2<0
			if (a.y < 0 && b.y < 0)
				yZeroPos = Math.abs(Math.abs(a.y) + b.y);
			// y1<0 && y2>=0
			if (a.y < 0 && b.y >= 0)
				yZeroPos = Math.abs(a.y) + b.y;

			Double distancePoint = Math.sqrt(xZeroPos * xZeroPos + yZeroPos
					* yZeroPos);
			return distancePoint.floatValue();
		} catch (Exception e) {
			log.error("Error ", e);
		}
		// error
		return -1f;
	}
}
